package utils;

import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;

/**
 * This class supplies standard logger creation, as well as a static method
 * to return a string of current time and date.
 * @author yuvalshu
 *
 */
public class Logging {
	/**
	 * Helper function to return string format of current date and time, in
	 * the following format: "yyyyMMdd-hhmmss"
	 */
	public static String getDateTime(){
		SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMdd-hhmmss");
		Date day = new Date();
		return formatter.format(day);
	}
	/**
	 * Returns a new logger instance, after opening a uniquly named log
	 * file int the word directory	
	 * @return
	 */
	public static Logger getLogger(){
		
		String fileName = "verifier_log_" + getDateTime() + ".log";
		try{
			File f = new File(fileName);
			if(!f.exists()) f.createNewFile();
			// create new log file with signature
			FileHandler handle = new FileHandler(fileName);
			// instance logger
			Logger log = Logger.getLogger("log_file");
			// set simple format
			handle.setFormatter(new SimpleFormatter());
			// attach handle to logger
			log.addHandler(handle);
			return log;
		}
		catch (IOException e) {
			// if no permission to open file
			return null;
		}
	}
}

   
  
